package com.example.emailcraft.controller;

import com.example.emailcraft.entity.common.Result;
import com.example.emailcraft.entity.request.LoginRequest;
import com.example.emailcraft.entity.request.RegisterRequest;
import com.example.emailcraft.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author scj
 * @since 2025-01-21
 */
@RestController
@RequestMapping("/api/v1/users")
public class UsersController {
    @Autowired
    private IUsersService userService;

    /***
     * 用户登录
     * @param request 登录请求对象
     * @param response 登录响应对象
     * @return 登录结果
     */
    @PostMapping("/login")
    public ResponseEntity<Result<Object>> login(@RequestBody LoginRequest request, HttpServletResponse response){
       return userService.login(request,response);
    }

    /***
     * 用户注册
     * @param request 注册请求对象
     * @return 注册结果
     */
    @PostMapping("/register")
    public ResponseEntity<Result<Object>> register(@RequestBody RegisterRequest request){
        return userService.register(request);
    }

    /***
     *  判断用户是否登录
     * @param request 请求对象
     * @return 登录结果
     */
    @GetMapping("/isLogin")
    public ResponseEntity<Result<Object>> IsLogin(HttpServletRequest request){
        return userService.IsLogin(request);
    }

}
